<template>
  <div class="dashboard-container">
    <el-button 
      class="back-home-button" 
      @click="goToHome"
      type="default"
      plain
    >
      <el-icon><ArrowLeft /></el-icon>
      返回首页
    </el-button>

    <div class="dashboard-grid">
      <!-- 欢迎卡片 -->
      <el-card class="welcome-card animate-card">
        <div class="welcome-content">
          <div class="welcome-left">
            <div class="welcome-header">
              <img src="http://127.0.0.1:9010/conference/conference_logo.jpg" alt="会议管理系统" class="welcome-logo">
              <div class="welcome-text-container">
                <h2 class="welcome-title">欢迎回来</h2>
                <h3 class="welcome-subtitle">{{ userInfo.fullName || userInfo.username }}</h3>
              </div>
            </div>
            <p class="welcome-text">在这里，您可以管理您的会议参与、查看个人信息，以及更多功能。</p>
          </div>
          <div class="welcome-right">
            <el-avatar 
              :size="80" 
              :src="userAvatar" 
              class="user-avatar"
              v-if="userInfo.avatar"
            >
              {{ userInfo.fullName?.charAt(0) || userInfo.username?.charAt(0) }}
            </el-avatar>
            <el-avatar 
              :size="80" 
              class="user-avatar"
              v-else
            >
              {{ userInfo.fullName?.charAt(0) || userInfo.username?.charAt(0) }}
            </el-avatar>
          </div>
        </div>
      </el-card>

      <!-- 快速统计卡片 -->
      <div class="stats-grid">
        <el-card class="stat-card animate-card" v-for="(stat, index) in stats" :key="index">
          <div class="stat-content">
            <el-icon class="stat-icon" :class="stat.color">
              <component :is="stat.icon" />
            </el-icon>
            <div class="stat-info">
              <h3 class="stat-value">{{ stat.value }}</h3>
              <p class="stat-label">{{ stat.label }}</p>
            </div>
          </div>
        </el-card>
      </div>

      <!-- 我的会议列表 -->
      <div class="meetings-section animate-card">
        <div class="section-header">
          <h2 class="section-title">我参与的会议</h2>
          <el-button type="primary" plain>查看全部</el-button>
        </div>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :md="8" v-for="meeting in meetings" :key="meeting.id">
            <el-card class="meeting-card" shadow="hover">
              <div class="meeting-status-badge" :class="meeting.status.type">
                {{ meeting.status.text }}
              </div>
              <h3 class="meeting-title">{{ meeting.title }}</h3>
              <div class="meeting-info">
                <p class="meeting-time">
                  <el-icon><Calendar /></el-icon>
                  {{ meeting.time }}
                </p>
                <p class="meeting-location">
                  <el-icon><Location /></el-icon>
                  {{ meeting.location }}
                </p>
              </div>
              <div class="meeting-footer">
                <el-button type="primary" text class="detail-btn">
                  查看详情
                  <el-icon class="arrow-icon"><ArrowRight /></el-icon>
                </el-button>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 个人信息卡片 -->
      <el-card class="profile-card animate-card">
        <div class="section-header">
          <h2 class="section-title">个人信息</h2>
          <div class="profile-actions">
            <el-button type="primary" plain>
              <el-icon><Edit /></el-icon>
              编辑资料
            </el-button>
            <el-button type="danger" plain>
              <el-icon><Lock /></el-icon>
              修改密码
            </el-button>
          </div>
        </div>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="用户名">{{ userInfo.username }}</el-descriptions-item>
          <el-descriptions-item label="全名">{{ userInfo.fullName || '未设置' }}</el-descriptions-item>
          <el-descriptions-item label="邮箱">{{ userInfo.email || '未设置' }}</el-descriptions-item>
          <el-descriptions-item label="电话">{{ userInfo.phone || '未设置' }}</el-descriptions-item>
        </el-descriptions>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { 
  Calendar, 
  Location, 
  ArrowLeft,
  ArrowRight,
  Edit,
  Lock,
  Timer,
  Document,
  Bell
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
// import request from '@/utils/request'

const router = useRouter()
const userInfo = reactive({})
const userAvatar = ref('')

// 统计数据
const stats = ref([
  {
    icon: 'Timer',
    value: '3',
    label: '进行中的会议',
    color: 'primary'
  },
  {
    icon: 'Document',
    value: '12',
    label: '历史会议',
    color: 'success'
  },
  {
    icon: 'Bell',
    value: '2',
    label: '待参加会议',
    color: 'warning'
  }
])

// 会议数据
const meetings = ref([
  {
    id: 1,
    title: '2024年度技术研讨会',
    time: '2024-03-20 14:00',
    location: '主会议室A',
    status: { text: '即将开始', type: 'upcoming' }
  },
  {
    id: 2,
    title: '项目进度评审会',
    time: '2024-03-22 10:00',
    location: '线上会议室',
    status: { text: '进行中', type: 'ongoing' }
  },
  {
    id: 3,
    title: '产品发布会',
    time: '2024-03-25 09:30',
    location: '国际会议中心',
    status: { text: '已报名', type: 'registered' }
  }
])

const goToHome = () => {
  router.push('/')
}

onMounted(() => {
  // 从localStorage获取用户信息
  const storedUserInfo = localStorage.getItem('userInfo')
  if (storedUserInfo) {
    const parsedUserInfo = JSON.parse(storedUserInfo)
    Object.assign(userInfo, parsedUserInfo)
    
    if (userInfo.avatar) {
      userAvatar.value = userInfo.avatar
    }
  } else {
    ElMessage.warning('未检测到登录信息，请重新登录')
    router.push('/login')
  }
  
  // 加载参会人员的会议列表
  loadMeetings()
})

const loadMeetings = async () => {
  try {
    // 此处应该调用API获取参会人员的会议列表
    // const response = await request({
    //   url: '/api/attendee/meetings',
    //   method: 'get'
    // })
    
    // 如果后端API准备好了，可以取消注释上面的代码
  } catch (error) {
    console.error('获取会议列表失败:', error)
  }
}
</script>

<style scoped>
.dashboard-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  position: relative;
}

.dashboard-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr;
}

.back-home-button {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #606266;
  border-color: #dcdfe6;
  z-index: 10;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.9);
}

.back-home-button:hover {
  color: #409EFF;
  border-color: #409EFF;
  background: rgba(255, 255, 255, 0.95);
  transform: translateX(-3px);
  transition: all 0.3s ease;
}

/* 欢迎卡片样式 */
.welcome-card {
  background: linear-gradient(135deg, #409EFF 0%, #36cfc9 100%);
  border: none;
  border-radius: 16px;
  overflow: hidden;
}

.welcome-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  color: white;
  padding: 24px;
}

.welcome-left {
  flex: 1;
  margin-right: 24px;
}

.welcome-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

.welcome-logo {
  width: 200px;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
  animation: logoFloat 3s ease-in-out infinite;
}

.welcome-logo:hover {
  transform: scale(1.05);
}

.welcome-text-container {
  flex: 1;
}

.welcome-title {
  font-size: 28px;
  margin: 0;
  font-weight: 600;
}

.welcome-subtitle {
  font-size: 20px;
  margin: 8px 0 0 0;
  opacity: 0.9;
}

.welcome-text {
  font-size: 16px;
  opacity: 0.8;
  line-height: 1.6;
  margin: 0;
}

.user-avatar {
  border: 4px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.user-avatar:hover {
  transform: scale(1.05);
}

/* 统计卡片样式 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.stat-card {
  border-radius: 12px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px;
}

.stat-icon {
  font-size: 32px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(64, 158, 255, 0.1);
}

.stat-icon.primary { color: #409EFF; background: rgba(64, 158, 255, 0.1); }
.stat-icon.success { color: #67C23A; background: rgba(103, 194, 58, 0.1); }
.stat-icon.warning { color: #E6A23C; background: rgba(230, 162, 60, 0.1); }

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: #303133;
}

.stat-label {
  font-size: 14px;
  color: #909399;
  margin: 0;
}

/* 会议卡片样式 */
.meetings-section {
  margin: 24px 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-title {
  font-size: 24px;
  margin: 0;
  color: #303133;
}

.meeting-card {
  position: relative;
  border-radius: 12px;
  margin-bottom: 20px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.meeting-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.meeting-status-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.meeting-status-badge.upcoming {
  background: rgba(103, 194, 58, 0.1);
  color: #67C23A;
}

.meeting-status-badge.ongoing {
  background: rgba(64, 158, 255, 0.1);
  color: #409EFF;
}

.meeting-status-badge.registered {
  background: rgba(230, 162, 60, 0.1);
  color: #E6A23C;
}

.meeting-title {
  font-size: 18px;
  margin: 16px 0;
  color: #303133;
}

.meeting-info {
  margin: 16px 0;
}

.meeting-time, .meeting-location {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  color: #606266;
  font-size: 14px;
}

.meeting-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.detail-btn {
  display: flex;
  align-items: center;
  gap: 4px;
}

.arrow-icon {
  transition: transform 0.3s ease;
}

.detail-btn:hover .arrow-icon {
  transform: translateX(4px);
}

/* 个人信息卡片样式 */
.profile-card {
  border-radius: 12px;
}

.profile-actions {
  display: flex;
  gap: 12px;
}

/* 动画效果 */
.animate-card {
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes logoFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* 响应式布局 */
@media screen and (max-width: 768px) {
  .dashboard-container {
    padding: 20px;
  }

  .back-home-button {
    position: static;
    margin-bottom: 20px;
  }

  .welcome-content {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 24px;
  }

  .welcome-left {
    margin-right: 0;
  }

  .welcome-header {
    flex-direction: column;
    gap: 16px;
  }

  .welcome-logo {
    width: 160px;
    height: auto;
  }

  .welcome-title {
    font-size: 24px;
  }

  .welcome-subtitle {
    font-size: 18px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .profile-actions {
    flex-direction: column;
    width: 100%;
  }

  .profile-actions .el-button {
    width: 100%;
  }
}

@media screen and (max-width: 480px) {
  .welcome-logo {
    width: 140px;
    height: auto;
  }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
  .back-home-button {
    background: rgba(0, 0, 0, 0.6);
  }

  .stat-card,
  .meeting-card,
  .profile-card {
    background: #1a1a1a;
  }

  .stat-value {
    color: #e5eaf3;
  }

  .meeting-title {
    color: #e5eaf3;
  }

  .section-title {
    color: #e5eaf3;
  }
}
</style> 